﻿using System.ComponentModel;
using JBeamLibrary.Events;
using JBeamLibrary.Types;
using JBeamLibrary.VehicleParts.Elements;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using JBeamLibrary.VehicleParts.Interfaces;

namespace JBeamLibrary.VehicleParts.Collections
{
    public class InternalCameraCollection : Collection<InternalCamera>, IVehicleGroupCollection<InternalCamera>
    {
        #region Fields

        public event ElementPropertyChangedEventHandler ElementPropertyChanged;

        #endregion

        #region CTORs

        /// <summary>Creates a new internal camera collection</summary>
        public InternalCameraCollection() { }

        /// <summary>Creates a new internal camera collection</summary>
        /// <param name="internalCameras"></param>
        public InternalCameraCollection(IEnumerable<InternalCamera> internalCameras)
        {
            AddRange(internalCameras);
        }

        #endregion

        #region Methods

        public new void Add(InternalCamera camera)
        {
            base.Add(camera);

            camera.PropertyChanged += (s, e) =>
            {
                if (ElementPropertyChanged != null)
                    ElementPropertyChanged(s, e);
            };
        }

        public void Add(Float3 offset, float fov, params string[] nodeIds)
        {
            Add(new InternalCamera(offset, fov, nodeIds));
        }

        public void AddRange(IEnumerable<InternalCamera> internalCameras)
        {
            foreach (var internalCamera in internalCameras)
                Add(internalCamera);
        }

        public void Remove(Float3 offset)
        {
            for (var i = 0; i < Count; i++)
            {
                var internalCamera = this[i];
                if(!internalCamera.Offset.Equals(offset))
                    continue;

                RemoveAt(i);
                i--;
            }
        }

        public new void Remove(InternalCamera element)
        {
            base.Remove(element);
        }

        #endregion
    }
}
